core: Map metadata from repository as trusted
authorColin Walters <walters@verbum.org>
Mon, 14 May 2012 19:49:49 +0000 (15:49 -0400)
committerColin Walters <walters@verbum.org>
Fri, 18 May 2012 20:30:44 +0000 (16:30 -0400)
ot_util_variant_map() assumed untrusted; add a boolean, and use it for
the repository internals.

src/libostree/ostree-repo.c
src/libotutil/ot-variant-utils.c
src/libotutil/ot-variant-utils.h
src/ostree/ostree-pull.c
src/ostree/ot-builtin-commit.c
src/ostree/ot-builtin-fsck.c
src/ostree/ot-builtin-pack.c
src/ostree/ot-builtin-show.c

index fcb0a5c9727535511db21b0fe2a50e02831609d9..9012cb89e659af22487c3e9b96a2b72ba3399af8 100644 (file)
@@ -1803,6 +1803,7 @@ static gboolean
 map_variant_file_check_header_string (GFile         *path,
                                       const GVariantType  *variant_type,
                                       const char    *expected_header,
+                                      gboolean       trusted,
                                       GVariant     **out_variant,
                                       GCancellable  *cancellable,
                                       GError       **error)
@@ -1811,7 +1812,7 @@ map_variant_file_check_header_string (GFile         *path,
   const char *header;
   ot_lvariant GVariant *ret_variant = NULL;
 
-  if (!ot_util_variant_map (path, variant_type, &ret_variant, error))
+  if (!ot_util_variant_map (path, variant_type, trusted, &ret_variant, error))
     goto out;
 
   g_variant_get_child (ret_variant, 0, "&s", &header);
@@ -1899,7 +1900,7 @@ list_pack_checksums_from_superindex_file (GFile         *superindex_path,
   GVariantIter *data_variant_iter = NULL;
 
   if (!ot_util_variant_map (superindex_path, OSTREE_PACK_SUPER_INDEX_VARIANT_FORMAT,
-                            &superindex_variant, error))
+                            TRUE, &superindex_variant, error))
     goto out;
   
   g_variant_get (superindex_variant, "(&s@a{sv}a(ayay)a(ayay))",
@@ -2293,7 +2294,7 @@ ostree_repo_resync_cached_remote_pack_indexes (OstreeRepo       *self,
   ret_uncached_data_indexes = g_ptr_array_new_with_free_func (g_free);
 
   if (!ot_util_variant_map (superindex_path, OSTREE_PACK_SUPER_INDEX_VARIANT_FORMAT,
-                            &superindex_variant, error))
+                            FALSE, &superindex_variant, error))
     goto out;
 
   if (!ostree_validate_structureof_pack_superindex (superindex_variant, error))
@@ -2438,7 +2439,7 @@ ostree_repo_map_cached_remote_pack_index (OstreeRepo       *self,
 
   cached_pack_path = get_pack_index_path (cache_dir, is_meta, pack_checksum);
   if (!ot_util_variant_map (cached_pack_path, OSTREE_PACK_INDEX_VARIANT_FORMAT,
-                            &ret_variant, error))
+                            FALSE, &ret_variant, error))
     goto out;
 
   ret = TRUE;
@@ -2470,7 +2471,7 @@ ostree_repo_add_cached_remote_pack_index (OstreeRepo       *self,
   if (!map_variant_file_check_header_string (cached_path,
                                              OSTREE_PACK_INDEX_VARIANT_FORMAT,
                                              "OSTv0PACKINDEX",
-                                             &input_index_variant,
+                                             FALSE, &input_index_variant,
                                              cancellable, error))
     goto out;
 
@@ -3437,7 +3438,7 @@ ostree_repo_load_pack_index (OstreeRepo    *self,
       path = get_pack_index_path (priv->pack_dir, is_meta, pack_checksum);
       if (!map_variant_file_check_header_string (path,
                                                  OSTREE_PACK_INDEX_VARIANT_FORMAT,
-                                                 "OSTv0PACKINDEX",
+                                                 "OSTv0PACKINDEX", TRUE,
                                                  &ret_variant,
                                                  cancellable, error))
         goto out;
@@ -3539,7 +3540,7 @@ ostree_repo_load_file (OstreeRepo         *self,
           ot_lvariant GVariant *archive_meta = NULL;
 
           if (!ot_util_variant_map (loose_path, OSTREE_FILE_HEADER_GVARIANT_FORMAT,
-                                    &archive_meta, error))
+                                    TRUE, &archive_meta, error))
             goto out;
 
           if (!ostree_file_header_parse (archive_meta, &ret_file_info, &ret_xattrs,
@@ -3826,28 +3827,61 @@ repo_find_object (OstreeRepo           *self,
   ot_lobj GFile *ret_stored_path = NULL;
   ot_lfree char *ret_pack_checksum = NULL;
 
-  if (out_stored_path)
+  /* Look up metadata in packs first, but content loose first.  We
+   * want to find loose content since that's preferable for
+   * hardlinking scenarios.
+   *
+   * Metadata is much more efficient packed.
+   */
+  if (OSTREE_OBJECT_TYPE_IS_META (objtype))
     {
-      object_path = ostree_repo_get_object_path (self, checksum, objtype);
-  
-      if (lstat (ot_gfile_get_path_cached (object_path), &stbuf) == 0)
+      if (out_pack_checksum)
         {
-          ret_stored_path = object_path;
-          object_path = NULL;
+          if (!find_object_in_packs (self, checksum, objtype,
+                                     &ret_pack_checksum, &ret_pack_offset,
+                                     cancellable, error))
+            goto out;
         }
-      else
+      if (!ret_pack_checksum || lookup_all)
         {
-          g_clear_object (&object_path);
+          object_path = ostree_repo_get_object_path (self, checksum, objtype);
+  
+          if (lstat (ot_gfile_get_path_cached (object_path), &stbuf) == 0)
+            {
+              ret_stored_path = object_path;
+              object_path = NULL;
+            }
+          else
+            {
+              g_clear_object (&object_path);
+            }
         }
     }
-  if (!ret_stored_path || lookup_all)
+  else
     {
-      if (out_pack_checksum)
+      if (out_stored_path)
         {
-          if (!find_object_in_packs (self, checksum, objtype,
-                                     &ret_pack_checksum, &ret_pack_offset,
-                                     cancellable, error))
-            goto out;
+          object_path = ostree_repo_get_object_path (self, checksum, objtype);
+  
+          if (lstat (ot_gfile_get_path_cached (object_path), &stbuf) == 0)
+            {
+              ret_stored_path = object_path;
+              object_path = NULL;
+            }
+          else
+            {
+              g_clear_object (&object_path);
+            }
+        }
+      if (!ret_stored_path || lookup_all)
+        {
+          if (out_pack_checksum)
+            {
+              if (!find_object_in_packs (self, checksum, objtype,
+                                         &ret_pack_checksum, &ret_pack_offset,
+                                         cancellable, error))
+                goto out;
+            }
         }
     }
   
@@ -3945,7 +3979,7 @@ ostree_repo_load_variant (OstreeRepo  *self,
   if (object_path != NULL)
     {
       if (!ot_util_variant_map (object_path, ostree_metadata_variant_type (objtype),
-                                &ret_variant, error))
+                                TRUE, &ret_variant, error))
         goto out;
     }
   else if (pack_checksum != NULL)
index 9e50ace63661bcc331b4054902d6e36be2004a7f..93b69b846742b9566342abc5a74c568281231f48 100644 (file)
@@ -108,10 +108,11 @@ ot_util_variant_take_ref (GVariant *variant)
  * Note the returned @out_variant is not floating.
  */
 gboolean
-ot_util_variant_map (GFile *src,
+ot_util_variant_map (GFile              *src,
                      const GVariantType *type,
-                     GVariant **out_variant,
-                     GError  **error)
+                     gboolean            trusted,
+                     GVariant          **out_variant,
+                     GError            **error)
 {
   gboolean ret = FALSE;
   const char *path = NULL;
@@ -126,7 +127,7 @@ ot_util_variant_map (GFile *src,
   ret_variant = g_variant_new_from_data (type,
                                          g_mapped_file_get_contents (mfile),
                                          g_mapped_file_get_length (mfile),
-                                         FALSE,
+                                         trusted,
                                          (GDestroyNotify) g_mapped_file_unref,
                                          mfile);
   mfile = NULL;
index 95ed2e9c5caa6989abf200c282e1ae7af2155e93..f03325ba2330128326eccda0c7c12bbe9e7df0ae 100644 (file)
@@ -59,6 +59,7 @@ gboolean ot_util_variant_save (GFile *dest,
 
 gboolean ot_util_variant_map (GFile *src,
                               const GVariantType *type,
+                              gboolean trusted,
                               GVariant **out_variant,
                               GError  **error);
 
index 652cff33c2599e381aa9e00255861df4f8eec589..67d10e72f6a941167513fb91eaadf452bc2eb321 100644 (file)
@@ -1008,8 +1008,8 @@ fetch_content (OtPullData           *pull_data,
                                cancellable, error))
         goto out;
 
-      if (!ot_util_variant_map (temp_path, OSTREE_FILE_HEADER_GVARIANT_FORMAT, &file_meta,
-                                error))
+      if (!ot_util_variant_map (temp_path, OSTREE_FILE_HEADER_GVARIANT_FORMAT, FALSE,
+                                &file_meta, error))
         goto out;
 
       if (!ostree_file_header_parse (file_meta, &file_info, &xattrs, error))
index 4fe367481a24ddce61747057da8a7fd0fdc257b5..a00c6027066c07220ce3986747999e32f76be5bf 100644 (file)
@@ -263,7 +263,8 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
       else if (metadata_bin_path)
         {
           metadata_f = ot_gfile_new_for_path (metadata_bin_path);
-          if (!ot_util_variant_map (metadata_f, G_VARIANT_TYPE ("a{sv}"), &metadata, error))
+          if (!ot_util_variant_map (metadata_f, G_VARIANT_TYPE ("a{sv}"), TRUE,
+                                    &metadata, error))
             goto out;
         }
       else
index 362f026077aa35402d259ad7c5cfbfa9d0ec2db2..04f801150ab3d39865c19f118020833a91c3adcf 100644 (file)
@@ -68,7 +68,7 @@ fsck_one_pack_file (OtFsckData        *data,
   pack_index_path = g_file_resolve_relative_path (ostree_repo_get_path (data->repo), path);
 
   if (!ot_util_variant_map (pack_index_path,
-                            OSTREE_PACK_INDEX_VARIANT_FORMAT,
+                            OSTREE_PACK_INDEX_VARIANT_FORMAT, FALSE,
                             &index_variant, error))
     goto out;
       
index 0c0d12b3a2d632b2af5da3695702ba04240fc2c8..2fc6defbb0230eeccc81099b29aaf6a6152f4618 100644 (file)
@@ -284,7 +284,7 @@ pack_one_meta_object (OtRepackData        *data,
   object_path = ostree_repo_get_object_path (data->repo, checksum, objtype);
 
   if (!ot_util_variant_map (object_path, ostree_metadata_variant_type (objtype),
-                            &metadata_v, error))
+                            TRUE, &metadata_v, error))
     goto out;
 
   ret_packed_object = g_variant_new ("(y@ayv)", (guchar) objtype,
index a6fe3f43f393946b843acf542042e7003fac3db7..8edc4c72de7f6b96828309a5d82750586bda7f44 100644 (file)
@@ -67,7 +67,7 @@ do_print_variant_generic (const GVariantType *type,
 
   f = ot_gfile_new_for_path (filename);
 
-  if (!ot_util_variant_map (f, type, &variant, error))
+  if (!ot_util_variant_map (f, type, TRUE, &variant, error))
     goto out;
 
   print_variant (variant);